using System.Configuration;
using System.Net.Configuration;
using System.Web;
using System.Web.Configuration;

namespace Webbness.Mvc.Config
{
    internal class SMTPSettings
    {
        private static SmtpSection _smtp;

        internal static SmtpSection SMTP
        {
            get
            {
                if (_smtp == null)
                {
                    Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
                    var settings = (MailSettingsSectionGroup) config.GetSectionGroup("system.net/mailSettings");
                    if (settings == null)
                        throw new ConfigurationErrorsException("system.net/mailSettings was not found.");

                    _smtp = settings.Smtp;
                }
                return _smtp;
            }
        }
    }
}